home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / DIKUMUD.ZIP / WEATHER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  9.9 KB  |  438 lines

  1. /*
  2.   SillyMUD Distribution V1.1b             (c) 1993 SillyMUD Developement
  3.  
  4.   See license.doc for distribution terms.   SillyMUD is based on DIKUMUD
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "protos.h"
  11.  
  12. /* uses */
  13.  
  14. extern struct time_info_data time_info;
  15. extern struct weather_data weather_info;
  16. extern struct room_data *room_db;
  17.  
  18. /*In this part. */
  19. void SaveTheWorld();
  20. void weather_and_time(int mode);
  21. void another_hour(int mode);
  22. void weather_change(void);
  23. void GetMonth( int month);
  24. void ChangeWeather( int change);
  25. void switch_light(byte why);  /* -DM 7/16/92 */
  26. void PulseMobiles(int type);
  27.  
  28. /* what stage is moon in?  (1 - 32) */
  29. unsigned char moontype;   
  30.  
  31. int gSeason;   /* global variable --- the season */
  32. int gMoonSet = 3;
  33. int gSunRise = 5;
  34. int gSunSet = 18;
  35. int gMoonRise = 22;
  36.  
  37. int gLightLevel = 4;  /* defaults to sunlight */
  38.  
  39. /* Here comes the code */
  40.  
  41. void weather_and_time(int mode)
  42. {
  43.   another_hour(mode);
  44.   if(mode)
  45.     weather_change();
  46. }
  47.  
  48. void another_hour(int mode)
  49. {
  50.   char moon[20], buf[100];
  51.   int tmp;
  52.   
  53.   time_info.hours++;
  54.   
  55.   tmp = time_info.hours;
  56.   
  57.   if (mode) {
  58.     
  59.     if (tmp == 0) {
  60.       SaveTheWorld();
  61.     }
  62.     if (tmp == gMoonRise) {
  63.       if (moontype < 4) {
  64.     strcpy(moon, "new");
  65.       } else if (moontype < 12) {
  66.     strcpy(moon, "waxing");
  67.       } else if (moontype < 20) {
  68.     strcpy(moon, "full");
  69.       } else  if (moontype < 28) {
  70.     strcpy(moon, "waning");
  71.       } else {
  72.     strcpy(moon, "new");
  73.       }
  74.       switch_light(MOON_RISE);
  75.       sprintf(buf,"The %s moon slowly rises from the western horizon.\n\r",moon);
  76.       send_to_outdoor(buf);
  77.       if((moontype > 16) && (moontype < 22)) {
  78.     gLightLevel++;   /* brighter during these moons */
  79.       }
  80.     }
  81.     if (tmp == gSunRise) {
  82.       weather_info.sunlight = SUN_RISE;
  83.       send_to_outdoor("The sun begins to rise from the western horizon.\n\r");
  84.     }
  85.     if (tmp == gSunRise+1) {
  86.       weather_info.sunlight = SUN_LIGHT;
  87.       switch_light(SUN_LIGHT);
  88.       send_to_outdoor("The day has begun.\n\r");
  89.     }
  90.     if (tmp == gSunSet) {
  91.       weather_info.sunlight = SUN_SET;
  92.       send_to_outdoor(
  93.               "The sun slowly disappears into the eastern horizon.\n\r");
  94.     }
  95.     if (tmp == gSunSet+1) {
  96.       weather_info.sunlight = SUN_DARK;
  97.       switch_light(SUN_DARK);
  98.       send_to_outdoor("The night has begun.\n\r");
  99.     }
  100.     if (tmp == gMoonSet) {
  101.       if((moontype > 15) && (moontype < 25)) {
  102.     switch_light(MOON_SET);
  103.         send_to_outdoor("Darkness once again fills the realm as the moon sets.\n\r");
  104.       } else {
  105.     send_to_outdoor("The moon sets\n\r");
  106.       }
  107.       
  108.     }
  109.     if (tmp == 12) {
  110.       send_to_outdoor("It is noon.\n\r");
  111.       SaveTheWorld();
  112.     }
  113.     
  114.     if (time_info.hours > 23)  /* Changed by HHS due to bug ???*/ {
  115.       time_info.hours -= 24;
  116.       time_info.day++;
  117.       switch(time_info.day) {
  118.       case 0:
  119.       case 6:
  120.       case 13:
  121.       case 20:
  122.       case 27:
  123.       case 34:
  124.     PulseMobiles(EVENT_WEEK);
  125.     break;
  126.       }  
  127.       /* check the season */
  128.       ChangeSeason(time_info.month);
  129.       
  130.       moontype++;
  131.       if (moontype > 32)
  132.     moontype = 1;
  133.       
  134.       if (time_info.day>34)  {
  135.     time_info.day = 0;
  136.     time_info.month++;
  137.     GetMonth(time_info.month);
  138.     PulseMobiles(EVENT_MONTH);
  139.     
  140.     if(time_info.month>16)               {
  141.       time_info.month = 0;
  142.       time_info.year++;
  143.     }
  144.       }
  145.       
  146.       ChangeSeason(time_info.month);      
  147.     }
  148.   }
  149. }
  150.  
  151. void ChangeSeason(int month)
  152. {
  153.   extern int gSeason;
  154.   switch (month){
  155.   case 0:
  156.   case 1:
  157.   case 2:
  158.   case 3:
  159.   case 16:
  160.     gSunRise = 9;  /* very late  */
  161.     gSunSet = 16;  /* very early */
  162.     gSeason = SEASON_WINTER;
  163.     break;
  164.   case 4:
  165.   case 5:
  166.   case 6:
  167.   case 7:
  168.     gSunRise = 7;  /* late  */
  169.     gSunSet = 18;  /* early */
  170.     gSeason = SEASON_SPRING;
  171.     break;
  172.   case 8:
  173.   case 9:
  174.   case 10:
  175.   case 11:
  176.     gSunRise = 5;  /* early  */
  177.     gSunSet = 20;  /* late   */
  178.     gSeason = SEASON_SUMMER;
  179.     break;
  180.   case 12:
  181.   case 13:
  182.   case 14:
  183.   case 15:
  184.     gSunRise = 7;  /* late  */
  185.     gSunSet = 18;  /* early */
  186.     gSeason = SEASON_FALL;
  187.     break;
  188.   default:
  189.     gSeason = SEASON_WINTER;
  190.     gSunRise = 9;  /* very late  */
  191.     gSunSet = 16;  /* very early */
  192.     break;
  193.   }
  194. }
  195.  
  196. void weather_change()
  197. {
  198.   int diff, change;
  199.   
  200.   if((time_info.month>=9)&&(time_info.month<=16))
  201.     diff=(weather_info.pressure>985 ? -2 : 2);
  202.   else
  203.     diff=(weather_info.pressure>1015? -2 : 2);
  204.   
  205.   weather_info.change += (dice(1,4)*diff+dice(2,6)-dice(2,6));
  206.   
  207.   weather_info.change = MIN(weather_info.change,12);
  208.   weather_info.change = MAX(weather_info.change,-12);
  209.   
  210.   weather_info.pressure += weather_info.change;
  211.   
  212.   weather_info.pressure = MIN(weather_info.pressure,1040);
  213.   weather_info.pressure = MAX(weather_info.pressure,960);
  214.   
  215.   change = 0;
  216.   
  217.   switch(weather_info.sky){
  218.   case SKY_CLOUDLESS :
  219.     {
  220.       if (weather_info.pressure<990)
  221.     change = 1;
  222.       else if (weather_info.pressure<1010)
  223.     if(dice(1,4)==1)
  224.       change = 1;
  225.       break;
  226.     }
  227.   case SKY_CLOUDY :
  228.     {
  229.       if (weather_info.pressure<970)
  230.     change = 2;
  231.       else if (weather_info.pressure<990)
  232.     if(dice(1,4)==1)
  233.       change = 2;
  234.     else
  235.       change = 0;
  236.       else if (weather_info.pressure>1030)
  237.     if(dice(1,4)==1)
  238.       change = 3;
  239.       
  240.       break;
  241.     }
  242.   case SKY_RAINING :
  243.     {
  244.       if (weather_info.pressure<970)
  245.     if(dice(1,4)==1)
  246.       change = 4;
  247.     else
  248.       change = 0;
  249.       else if (weather_info.pressure>1030)
  250.     change = 5;
  251.       else if (weather_info.pressure>1010)
  252.     if(dice(1,4)==1)
  253.       change = 5;
  254.       
  255.       break;
  256.     }
  257.   case SKY_LIGHTNING :
  258.     {
  259.       if (weather_info.pressure>1010)
  260.     change = 6;
  261.       else if (weather_info.pressure>990)
  262.     if(dice(1,4)==1)
  263.       change = 6;
  264.       
  265.       break;
  266.     }
  267.     default : 
  268.       {
  269.     change = 0;
  270.     weather_info.sky=SKY_CLOUDLESS;
  271.     break;
  272.       }
  273.   }
  274.   
  275.   ChangeWeather(change);
  276.   
  277. }
  278.  
  279. void ChangeWeather( int change)
  280. {
  281.  
  282.    if (change < 0)
  283.       change = 0;
  284.    if (change > 7)
  285.      change = 6;
  286.    
  287.    switch(change){
  288.    case 0 : break;
  289.    case 1 :
  290.      {
  291.        send_to_outdoor("The sky is getting cloudy.\n\r");
  292.        weather_info.sky=SKY_CLOUDY;
  293.        break;
  294.      }
  295.    case 2 :
  296.      {
  297.        if ((time_info.month > 3) && (time_info.month < 14)) {
  298.      send_to_desert("A strong wind begins to sweep across the land\n\r");
  299.          send_to_arctic("It starts to snow\n\r");
  300.      send_to_out_other("It starts to rain.\n\r");
  301.        } else {
  302.      send_to_desert(
  303.           "A strong, cold wind begins to sweep across the land\n\r");
  304.          send_to_arctic("It starts to snow heavily.\n\r");
  305.      send_to_out_other("It starts to snow.\n\r");
  306.        }
  307.        weather_info.sky=SKY_RAINING;
  308.        break;
  309.      }
  310.    case 3 :
  311.      {
  312.        send_to_outdoor("The clouds disappear.\n\r");
  313.        weather_info.sky=SKY_CLOUDLESS;
  314.        break;
  315.      }
  316.    case 4 :
  317.      {
  318.        if ((time_info.month > 3) && (time_info.month < 14)) {
  319.      send_to_desert(
  320.           "You are caught in a blinding sandstorm\n\r");
  321.          send_to_arctic("You are caught in a blinding blizzard\n\r");
  322.      send_to_out_other("You are caught in lightning storm.\n\r");
  323.        } else  {
  324.      send_to_desert(
  325.           "You are caught in a blinding sandstorm\n\r");
  326.          send_to_arctic("You are caught in a blizzard\n\r");
  327.      send_to_out_other("You are caught in a blizzard. \n\r" );
  328.        }
  329.        weather_info.sky=SKY_LIGHTNING;
  330.        break;
  331.      }
  332.    case 5 :
  333.      {
  334.        if ((time_info.month > 3) && (time_info.month < 14))  {
  335.      send_to_desert(
  336.           "The sandstorm slowly quiets\n\r");
  337.          send_to_arctic("The snowstorm slowly dies down\n\r");
  338.      send_to_out_other("The rainstorm slowly dies down\n\r" );
  339.        } else  {
  340.      send_to_desert(
  341.           "The sandstorm slowly quiets\n\r");
  342.          send_to_arctic("It has stopped snowing\n\r");
  343.      send_to_out_other("The snow has stopped. \n\r");
  344.        }
  345.        weather_info.sky=SKY_CLOUDY;
  346.        break;
  347.      }
  348.    case 6 :
  349.      {
  350.        if ((time_info.month > 3) && (time_info.month < 14)) {
  351.      send_to_desert(
  352.           "The sandstorm dies down, but the wind continues\n\r");
  353.          send_to_arctic("The blizzard has died down, but the snow continutes\n\r");
  354.      send_to_out_other(
  355.                 "The lightning has gone, but it is still raining.\n\r");
  356.        } else {
  357.      send_to_desert(
  358.           "The sandstorm dies down, but the wind continues\n\r");
  359.      send_to_arctic("The blizzard is over, but it is still snowing.\n\r");
  360.      send_to_out_other("The blizzard is over, but it is still snowing.\n\r");
  361.        }
  362.        weather_info.sky=SKY_RAINING;
  363.        break;
  364.      }
  365.      default : break;
  366.    }
  367.  }
  368.  
  369. void GetMonth( int month)
  370. {
  371.    if (month < 0)
  372.       return;
  373.  
  374.    if (month <= 1) {
  375.        send_to_outdoor(" It is bitterly cold outside\n\r");
  376.       }
  377.    else if (month <=2) {
  378.        send_to_outdoor(" It is very cold \n\r");
  379.       }
  380.    else if (month <=3) {
  381.        send_to_outdoor(" It is chilly outside \n\r");
  382.       }
  383.    else if (month == 4) {
  384.         send_to_outdoor(" The flowers start to bloom \n\r");
  385.         PulseMobiles(EVENT_SPRING);
  386.    }
  387.    else if (month == 8) {
  388.         send_to_outdoor(" It is warm and humid. \n\r");
  389.         PulseMobiles(EVENT_SUMMER);
  390.       }
  391.    else if (month == 12) {
  392.         send_to_outdoor(" It starts to get a little windy \n\r");
  393.         PulseMobiles(EVENT_FALL);
  394.       }
  395.    else if (month == 13) {
  396.         send_to_outdoor(" The air is getting chilly \n\r"); 
  397.       }
  398.    else if (month == 14) {
  399.         send_to_outdoor(" The leaves start to change colors. \n\r");
  400.       }
  401.    else if (month == 15) {
  402.         send_to_outdoor(" It starts to get cold \n\r");
  403.       }
  404.    else if (month == 16) {
  405.         send_to_outdoor(" It is bitterly cold outside \n\r");
  406.         PulseMobiles(EVENT_WINTER);
  407.       }
  408. }
  409.  
  410. void switch_light(byte why)
  411. {
  412.  extern int gLightLevel;
  413.  
  414.  
  415.  switch(why) {
  416.  case MOON_SET:
  417.    log_sev("setting all rooms to dark", 2);
  418.    gLightLevel = 0;
  419.    break;
  420.  case SUN_LIGHT:
  421.    log_sev("setting all rooms to light", 2);
  422.    gLightLevel = 4;
  423.    break;
  424.  case SUN_DARK:
  425.    log_sev("setting all rooms to dark", 2);
  426.    gLightLevel = 0;
  427.    break;
  428.  case MOON_RISE:
  429.    log_sev("setting all non-forest to light", 2);
  430.    gLightLevel = 1;
  431.    break;
  432.  default:
  433.    log_sev("Unknown switch on switch_light", 2);
  434.    break;
  435.  }
  436.  
  437. }
  438.